﻿function DataGridEx(opt) {
    if (typeof (opt) == "undefined" || typeof (opt) == undefined) {
        alert("没有为DataGrid提供必要的参数！");
        return;
    }
    if (opt == null) {
        alert("没有为DataGrid提供必要的参数！");
        return;
    }
    if (typeof (opt) != "object") {
        alert("DataGrid参数错误！");
        return;
    }
    if (typeof (opt.Id) == "undefined" || typeof (opt.Id) == undefined) {
        alert("没有为DataGrid提供Id参数！");
        return;
    }
    if (typeof (opt.Id) != "string") {
        alert("Id参数类型不正确！");
        return;
    }
    if (!document.getElementById(opt.Id)) {
        $("body").prepend("<table id=\"" + opt.Id + "\"></table>");
    }
    if (!document.getElementById(opt.Id)) {
        return;
    }
    var thisObj = this;
    this.DataGridId = opt.Id;
    var gridId = opt.Id;
    this.Title = typeof (opt.Title) == "string" ? opt.Title : "";
    this.Collapsible = typeof (opt.Collapsible) == "boolean" ? opt.Collapsible : false;
    this.SortName = typeof (opt.SortName) == "string" ? opt.SortName : null,
    this.SortOrder = typeof (opt.SortOrder) == "string" ? opt.SortOrder : "asc";
    this.RemoteSort = typeof (opt.RemoteSort) == "boolean" ? opt.RemoteSort : true;
    this.IdField = typeof (opt.IdField) == "string" ? opt.IdField : "";
    this.Url = typeof (opt.Url) == "string" ? opt.Url : "";
    this.Pagination = typeof (opt.Pagination) == "boolean" ? opt.Pagination : true;
    this.Rownumbers = typeof (opt.Rownumbers) == "boolean" ? opt.Rownumbers : false;
    this.Toolbar = (typeof (opt.Toolbar) != "undefined" && typeof (opt.Toolbar) != undefined) ? opt.Toolbar : null;
    this.Columns = (typeof (opt.Columns) != "undefined" && typeof (opt.Columns) != undefined) ? opt.Columns : undefined;
    this.PageSize = typeof (opt.PageSize) == "number" ? opt.PageSize : 10;
    this.PageList = (typeof (opt.PageList) != "undefined" && typeof (opt.PageList) != undefined) ? opt.PageList : [10, 20, 30, 40, 50];
    this.QueryParams = (typeof (opt.QueryParams) != "undefined" && typeof (opt.QueryParams) != undefined) ? opt.QueryParams : {};
    this.AllowEdit = typeof (opt.AllowEdit) == "boolean" ? opt.AllowEdit : false;
    this.AllowDbl = typeof (opt.AllowDbl) == "boolean" ? opt.AllowDbl : false;
    this.RowEndEditCallback = typeof (opt.RowEndEditCallback) == "function" ? opt.RowEndEditCallback : null;
    this.LoadSuccessCallBack = typeof (opt.LoadSuccessCallBack) == "function" ? opt.LoadSuccessCallBack : null;
    this.DblClickNew = typeof (opt.DblClickNew) == "function" ? opt.DblClickNew : null;
    this.ClickRowNew= typeof (opt.ClickRowNew) == "function" ? opt.ClickRowNew : null;
    this.Fit = typeof (opt.Fit) == "boolean" ? opt.Fit : true;
    this.FitColumns = typeof (opt.FitColumns) == "boolean" ? opt.FitColumns : true;
    this.Width = typeof (opt.Width) == "number" ? opt.Width : 400;
    this.Height = typeof (opt.Height) == "number" ? opt.Height : 300;
    this.NoWrap = typeof (opt.NoWrap) == "boolean" ? opt.NoWrap : true;
    this.AutoRowHeight = typeof (opt.AutoRowHeight) == "boolean" ? opt.AutoRowHeight : false;
    this.EditIndex = undefined;
    this.ShowCheckBox = typeof (opt.ShowCheckBox) == "boolean" ? opt.ShowCheckBox : false;
    this.ShowRadio = typeof (opt.ShowRadio) == "boolean" ? opt.ShowRadio : false;
    this.FrozenColumns = (typeof (opt.FrozenColumns) != "undefined" && typeof (opt.FrozenColumns) != undefined) ? opt.FrozenColumns : undefined;
    this.CheckBoxValueField = typeof (opt.CheckBoxValueField) == "string" ? opt.CheckBoxValueField : "Id";
    this.OnlySelectSingle = typeof (opt.OnlySelectSingle) == "boolean" ? opt.OnlySelectSingle : false;
    this.LoadLocalData = typeof (opt.LoadLocalData) == "boolean" ? opt.LoadLocalData : false;
    this.LocalData = opt.LocalData || {};
    this.OnBeforeOnclick = typeof (opt.OnBeforeOnclick) == "function" ? opt.OnBeforeOnclick : function () { return true; };
    this.keepEditStatus = (typeof (opt.keepEditStatus) != "undefined" && typeof (opt.keepEditStatus) != undefined) ? opt.keepEditStatus : false;
    resetFrozenColumns(thisObj); ;
    function resetFrozenColumns(objGridEx) {
        if (!objGridEx.ShowCheckBox) { return; }
        var columns = [[]];
        if (objGridEx.FrozenColumns) {
            extend(columns, objGridEx.FrozenColumns);
        }
        var sT = '<input value="selAll" type="checkbox" id="' + gridId + 'SellAll" name="' + gridId + 'SellAll" />全选';
        if (objGridEx.OnlySelectSingle) {
            sT = '选择';
        }
        var col = { align: "center", title: sT, field: objGridEx.CheckBoxValueField, width: 55, sortable: false,
            formatter: function (value, row, index) {
                return '<input type="checkbox" name="' + gridId + 'SelRow" value="' + value + '" />';
            }
        };
        columns[0].unshift(col);
        objGridEx.FrozenColumns = columns;
    };


    function getType(o) {
        var _t;
        return ((_t = typeof (o)) == "object" ? o == null && "null" || Object.prototype.toString.call(o).slice(8, -1) : _t).toLowerCase();
    };
    function extend(destination, source) {
        for (var p in source) {
            if (getType(source[p]) == "array" || getType(source[p]) == "object") {
                destination[p] = getType(source[p]) == "array" ? [] : {};
                arguments.callee(destination[p], source[p]);
            }
            else {
                destination[p] = source[p];
            }
        }
    };
};

function GridException() {
    this.ErrorDetail = null;
    this.ShowErrorDetail = function () {
        var thisObj = this;
        var err = thisObj.ErrorDetail;
        var winId = parseInt(Math.random(), 10);
        winId = "win" + winId;
        winId = String(winId);
        var opener = window.open("", winId);
        var errText = err.responseText;
        errText = errText.replaceAll("<!--", "");
        errText = errText.replaceAll("-->", "");
        opener.document.write(errText);
        opener.document.title = "Ajax调用错误详细信息";
    }
};
var gridExceptionObj = new GridException();

DataGridEx.prototype.Show = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    $("#" + gridId).datagrid({
        onLoadError: function () {
            return;
            var s = "";
            for (var i = 0; i < arguments.length; i++) {
                if (i == 0) {
                    if (arguments[i].toSource) {
                        s = arguments[i]; // toSource();
                        thisObj.ErrorDetail = arguments[i];
                    }
                    else {
                        s = arguments[i];
                        thisObj.ErrorDetail = arguments[i];
                    }
                }
                else {
                    s += "<br>" + arguments[i];
                }
            }
            gridExceptionObj.ErrorDetail = thisObj.ErrorDetail;

            if (typeof (gridExceptionObj.ErrorDetail) == "object") {
                if (typeof (gridExceptionObj.ErrorDetail.responseText) == "string") {
                    if ("UnLogined" == gridExceptionObj.ErrorDetail.responseText) {
                        $.messager.alert('提示', '您尚未登录或登录已经超时！', 'info', function () {
                            top.location = "/";
                        });
                        return;
                    }
                    if ("Unauthorized" == gridExceptionObj.ErrorDetail.responseText) {
                        $.messager.alert('提示', '对不起，您没有权限访问此功能，详请请联系管理员！', 'error', function () { });
                        return;
                    }
                    s += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + "<a href=\"javascript:;\" onclick=\"" + "gridExceptionObj" + ".ShowErrorDetail();\">查看详细</a><br>";
                    $.messager.alert('提示', s, 'error');
                    return;
                }
                s += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + "<a href=\"javascript:;\" onclick=\"" + "gridExceptionObj" + ".ShowErrorDetail();\">查看详细</a><br>";
                $.messager.alert('提示', s, 'error');
                return;
            }

            s += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + "<a href=\"javascript:;\" onclick=\"" + "gridExceptionObj" + ".ShowErrorDetail();\">查看详细</a><br>";
            $.messager.alert('提示', s, 'error');
        },
        title: this.Title,
        fit: this.Fit,
        fitColumns: this.FitColumns,
        width: this.Width,
        height: this.Height,
        striped: true,
        //iconCls: 'icon-save',
        singleSelect: true,
        checkOnSelect: false,
        selectOnCheck: false,
        nowrap: this.NoWrap,
        autoRowHeight: this.AutoRowHeight,
        collapsible: this.Collapsible,
        sortName: this.SortName,
        sortOrder: this.SortOrder,
        remoteSort: this.RemoteSort,
        showFooter: false,
        idField: this.IdField,
        pagination: this.Pagination,
        rownumbers: false,
        toolbar: this.Toolbar,
        pageSize: this.PageSize,
        pageList: this.PageList,
        frozenColumns: this.FrozenColumns,
        columns: this.Columns,
        queryParams: this.QueryParams,
        nowrap: this.nowrap,
        url: this.Url,
        //		rowStyler: function(index,row){
        //				return 'height:50px;';
        //		},
        //      onDblClickRow: this.AllowEdit ? function (rowIndex, rowData) { rowClick(rowIndex, rowData, thisObj); } : function () { },  
        onDblClickRow: this.AllowDbl ? function (rowIndex, rowData) { rowDblClick(rowIndex, rowData, thisObj); } : this.AllowEdit ? function (rowIndex, rowData) { rowClick(rowIndex, rowData, thisObj); } : function () { },
        onClickRow: function (rowIndex, rowData) { 
        	  if (typeof (thisObj.ClickRowNew) == "function") {
                  thisObj.ClickRowNew(data);
              }
        },
        onLoadSuccess: function (data) {
            $("input[type='checkbox']").click(function (evt) {
                evt.stopPropagation();
            });
            $("input[type='checkbox']").change(function (evt) {
                evt.stopPropagation();
            });

            $("#" + thisObj.DataGridId + "SellAll").click(function (evt) {
                var ckbObj = this;
                thisObj.SellAll(ckbObj);
                evt.stopPropagation();
            });


            $("input[type='checkbox'][name='" + thisObj.DataGridId + "SelRow']").each(function (index, ckbObj) {
                $(ckbObj).click(function (evt) { thisObj.SelOne(ckbObj); evt.stopPropagation(); });
            });

            if (typeof (thisObj.LoadSuccessCallBack) == "function") {
                thisObj.LoadSuccessCallBack(data);
            }
        }
    });

    setOrderStyle(this.DataGridId, this.SortName, this.SortOrder);

    function setOrderStyle(gridId, sortName, sortOrder) {
        var tableObj = $("#" + gridId);
        if (typeof (tableObj) == "undefined" || tableObj == null) { return; }
        var areaObj = tableObj.parents('.datagrid:eq(0)');
        if (typeof (areaObj) == "undefined" || areaObj == null) { return; }
        var obj = areaObj.find("td[field='" + sortName + "']:eq(0)");
        if (typeof (obj) == "undefined" || obj == null || obj.length == 0) {
            //alert("没有找到对应项");
            return;
        }
        if (typeof (obj) == "undefined" || typeof (obj) == undefined || obj == null) {
            return;
        }
        if (typeof (obj.length) != "number") {
            return;
        }
        var objTd = obj;
        if (sortOrder == "desc") {
            objTd.find(".datagrid-cell:eq(0)").addClass("datagrid-sort-desc");
        }
        else {
            objTd.find(".datagrid-cell:eq(0)").addClass("datagrid-sort-asc");
        }
    };
    var p = $("#" + this.DataGridId).datagrid('getPager');
    var GID = this.DataGridId;
    $(p).pagination({
        onBeforeRefresh: function () {
            //            alert('before refresh');
        },
        onChangePageSize: function (pageSize) {
            var queryParams = new Object();
            if (document.getElementById("GridSearchForm")) {
                var fields = $("#GridSearchForm").serialize(); // Array
                var arr1 = fields.split("&");
                for (var arrIndex1 = 0; arrIndex1 < arr1.length; arrIndex1++) {
                    var arr2 = arr1[arrIndex1].split("=");
                    if (typeof (queryParams[arr2[0]]) == "string") {
                        queryParams[arr2[0]] = queryParams[arr2[0]] + "," + arr2[1];
                    }
                    else {
                        queryParams[arr2[0]] = arr2[1];
                    }
                }
            }
            if (typeof (querys) == "object") {
                for (var attName in querys) {
                    var pageName = getPageName();
                    if (pageName == "stationlist") {
                        if (attName != "ProjectId") {
                            queryParams[attName] = querys[attName];
                        }
                    }
                    else {
                        queryParams[attName] = querys[attName];
                    }
                }
            }
            if (thisObj.LoadLocalData) {
                $("#" + GID).datagrid('loadData', thisObj.LocalData);
            } else {
                $("#" + GID).datagrid('load', $.extend(queryParams, thisObj.QueryParams));
            }

        }
    });

    function rowClick() {
        var oldIndex = null;
        var rowIndex = arguments[0];
        var rowData = arguments[1];
        var objGridEx = arguments[2];
        if (!objGridEx.OnBeforeOnclick(rowData)) {
            return;
        }
        var gridId = objGridEx.DataGridId;
        if (!objGridEx) { return; }
       // if (rowIndex != objGridEx.EditIndex) {
            $("#" + gridId).datagrid('selectRow', rowIndex).datagrid('beginEdit', rowIndex);
            if (typeof (objGridEx.DblClickNew) == "function") {
                objGridEx.DblClickNew(rowIndex, rowData, objGridEx);
            }
            oldIndex = objGridEx.EditIndex;
            objGridEx.EditIndex = rowIndex;
            if (objGridEx.keepEditStatus == false) {
                $.each(objGridEx.GetRows(), function (i, o) {
                    if (i !== rowIndex) {
                        $("#" + gridId).datagrid('endEdit', i)
                    }
                });
            }
        //}
    };
    return gridId;
};
function rowDblClick() {
    var oldIndex = null;
    var rowIndex = arguments[0];
    var rowData = arguments[1];
    var objGridEx = arguments[2];
    if (!objGridEx.OnBeforeOnclick(rowData)) {
        return;
    }

    var gridId = objGridEx.DataGridId;
    var id = rowData[objGridEx.CheckBoxValueField];
    if (!objGridEx) { return; }

    EditPRWin(id);

}
DataGridEx.prototype.SelOne = function () {
    var chkObj = arguments[0];
    var gridId = this.DataGridId;
    if (!this.OnlySelectSingle) {
        return;
    }
    if (!chkObj.checked) {
        return;
    }
    var b = chkObj.checked;
    $("input[type='checkbox'][name='" + gridId + "SelRow']").attr("checked", false);
    chkObj.checked = b;
};

DataGridEx.prototype.SellAll = function () {
    var gridId = this.DataGridId;
    var chk = false;
    if (arguments.length == 0) {
        chk = true;
    }
    else {
        if (typeof (arguments[0]) == "boolean") {
            chk = arguments[0];
        }
        else {
            chk = arguments[0].checked;
        }
    }
    $("#" + gridId + "SellAll").attr("checked", chk);
    $("input[type=checkbox][name=" + gridId + "SelRow]").attr("checked", chk);
};

DataGridEx.prototype.EndRowEditing = function () {
    var gridId = this.DataGridId;
    if (this.EditIndex == undefined) {
        return true;
    }
    var thisObj = this;
    if ($("#" + gridId).datagrid('validateRow', this.EditIndex)) {
        var cIndex = this.EditIndex;
        this.EditIndex = undefined;
        if (typeof (this.RowEndEditCallback) == "function") {
            this.RowEndEditCallback(thisObj, cIndex);
        }
        var chk = $("input[type='checkbox'][name='" + gridId + "SelRow']:eq(" + cIndex + ")").attr("checked");
        if (typeof (chk) == "undefined") {
            $("input[type='checkbox'][name='" + gridId + "SelRow']:eq(" + cIndex + ")").attr("checked", false);
        }
        else {
            if (typeof (chk) == "string" && chk == "checked") {
                $("input[type='checkbox'][name='" + gridId + "SelRow']:eq(" + cIndex + ")").attr("checked", true);
            }
            else {
                $("input[type='checkbox'][name='" + gridId + "SelRow']:eq(" + cIndex + ")").attr("checked", false);
            }
        }
        $("#" + gridId).datagrid('endEdit', cIndex);
        return true;
    } else {
        $.messager.alert('提示', '您没有录入必要的数据或数据录入不符合要求！<br>', 'error');
        return false;
    }
};

DataGridEx.prototype.AddRow = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    if (this.EndRowEditing()) {
        $("#" + gridId).datagrid('appendRow', {});
        this.EditIndex = $("#" + gridId).datagrid('getRows').length - 1;
        $("#" + gridId).datagrid('selectRow', this.EditIndex).datagrid('beginEdit', this.EditIndex);
    }
};


DataGridEx.prototype.BeginEdit = function () {
    var gridId = this.DataGridId;
    $("#" + gridId).datagrid('selectRow', this.EditIndex).datagrid('beginEdit', this.EditIndex);
}

DataGridEx.prototype.EndEdit = function () {
    var gridId = this.DataGridId;
    $("#" + gridId).datagrid('selectRow', this.EditIndex).datagrid('endEdit', this.EditIndex);
}

DataGridEx.prototype.GetRows = function () {
    var gridId = this.DataGridId;
    return $("#" + gridId).datagrid('getRows');
};

DataGridEx.prototype.GetEditor = function (options) {
    var gridId = this.DataGridId;
    return $("#" + gridId).datagrid('getEditor', options);
};

DataGridEx.prototype.DelEditingRow = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    if (this.EditIndex == undefined) { return; }
    $("#" + gridId).datagrid('cancelEdit', this.EditIndex).datagrid('deleteRow', this.EditIndex);
    this.EditIndex = undefined;
};

DataGridEx.prototype.Load = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    if (arguments.length == 0) {
        $("#" + gridId).datagrid('load', {});
    }
    else {
        if (this.QueryParams) {
            $.extend(arguments[0], this.QueryParams);
        }
        $("#" + gridId).datagrid('load', arguments[0]);
    }
    thisObj.EditIndex = undefined;
};

DataGridEx.prototype.ReLoad = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    if (arguments.length == 0) {
        $("#" + gridId).datagrid('reload', {});
    }
    else {
        if (this.QueryParams) {
            $.extend(arguments[0], this.QueryParams);
        }
        $("#" + gridId).datagrid('reload', arguments[0]);
    }
    thisObj.EditIndex = undefined;
};

DataGridEx.prototype.LoadData = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    if (arguments.length == 0) {
        $("#" + gridId).datagrid('loadData', {});
    }
    else {
        $("#" + gridId).datagrid('loadData', arguments[0]);
    }
    thisObj.EditIndex = undefined;
};

DataGridEx.prototype.AcceptChanges = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    if (this.EndRowEditing()) {
        $('#' + gridId).datagrid('acceptChanges');
    }
};

DataGridEx.prototype.RejectChanges = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    $('#' + gridId).datagrid('rejectChanges');
    this.EditIndex = undefined;
};

DataGridEx.prototype.GetChanges = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    var changesRows = {
        Inserted: [],
        Updated: [],
        Deleted: []
    };
    //    if (!this.EndRowEditing()) {
    //        return changesRows;
    //    }
    //var rows = $('#' + gridId).datagrid('getChanges');
    var insertRows = $('#' + gridId).datagrid('getChanges', 'inserted');
    var appendRows = $('#' + gridId).datagrid('getChanges', 'appended');
    var updateRows = $('#' + gridId).datagrid('getChanges', 'updated');
    var deleteRows = $('#' + gridId).datagrid('getChanges', 'deleted');

    if (insertRows.length > 0) {
        for (var i = 0; i < insertRows.length; i++) {
            changesRows.Inserted.push(insertRows[i]);
        }
        for (var i = 0; i < appendRows.length; i++) {
            changesRows.Inserted.push(appendRows[i]);
        }
    }
    if (updateRows.length > 0) {
        for (var k = 0; k < updateRows.length; k++) {
            changesRows.Updated.push(updateRows[k]);
        }
    }
    if (deleteRows.length > 0) {
        for (var j = 0; j < deleteRows.length; j++) {
            changesRows.Deleted.push(deleteRows[j]);
        }
    }
    return changesRows;
};

DataGridEx.prototype.GetCheckedRows = function () {
    var retRows = [];
    var selIndex = [];
    var gridId = this.DataGridId;
    var thisObj = this;
    var showCheckBox = thisObj.ShowCheckBox;
    var allRows = $('#' + gridId).datagrid('getRows');
    if ((!allRows) || !(allRows.length)) {
        if (arguments.length == 0) {
            return "";
        }
        else {
            if (typeof (arguments[0]) != "string") {
                return "";
            }
            else {
                if (arguments[0] == "GetAllData") {
                    return retRows;
                }
                else {
                    if (arguments[0] == "GetIndex") {
                        return selIndex;
                    }
                    else {
                        return "";
                    }
                }
            }
        }
    }

    var checkBoxValueField = thisObj.CheckBoxValueField;
    var row;
    var checkBoxValue;
    var sJs;
    var sValues = "";
    for (var i = 0; i < allRows.length; i++) {
        row = allRows[i];
        sJs = "checkBoxValue = row." + checkBoxValueField;
        eval(sJs);
        var chkObj = $("input[type='checkbox'][name='" + gridId + "SelRow']:eq(" + i + ")");
        if (chkObj.length != 1) {
            continue;
        }
        if (chkObj[0].checked) {
            sValues = sValues == "" ? checkBoxValue : sValues + "," + checkBoxValue;
            retRows.push(row);
            selIndex.push(i);
        }
    }

    if (arguments.length == 0) {
        return sValues;
    }
    else {
        if (typeof (arguments[0]) != "string") {
            return sValues;
        }
        else {
            if (arguments[0] == "GetAllData") {
                return retRows;
            }
            else {
                if (arguments[0] == "GetIndex") {
                    return selIndex;
                }
                else {
                    return sValues;
                }
            }
        }
    }
};

DataGridEx.prototype.GetCurrentPageRowCount = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    var allRows = $('#' + gridId).datagrid('getRows');
    return allRows.length;
};

DataGridEx.prototype.GetCheckedRowCount = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    var r = thisObj.GetCheckedRows("GetIndex");
    return r.length;
};

DataGridEx.prototype.DeleteCheckedRows = function () {
    var gridId = this.DataGridId;
    var thisObj = this;
    var selIndexArr = thisObj.GetCheckedRows("GetIndex");
    if (selIndexArr.length == 0) {
        return;
    }
    for (var i = selIndexArr.length - 1; i >= 0; i--) {
        var curIndex = selIndexArr[i];
        $('#' + gridId).datagrid('cancelEdit', curIndex).datagrid('unselectRow', curIndex).datagrid('deleteRow', curIndex);
    }
};

//var grid = $('#datagrid');
//var options = grid.datagrid('getPager').data("pagination").options;
//var curr = options.pageNumber;
//var total = options.total;
//var max = Math.ceil(total / options.pageSize);  
// http://www.bhcode.net/article/20120327/22426.html



function getCommonGridOpt() {
    var opt = new Object();
    opt.Id = "listDataEx1";
    opt.Title = "列表";
    opt.Collapsible = true;
    //opt.FrozenColumns = getFrozenColumns();
    //opt.Columns = getColumns();
    opt.Url = "";
    opt.Fit = true;
    opt.FitColumns = true;
    opt.ShowCheckBox = true;
    //opt.CheckBoxValueField = "DicId";
    opt.OnlySelectSingle = false;
    //opt.SortName = "OrderId";
    //opt.SortOrder = "Asc";
    opt.PageSize = 50;
    opt.PageList = [10, 50, 100, 200];
    //opt.IdField = "OrderId";
    opt.Pagination = true;
    opt.Rownumbers = false;
    opt.Toolbar = "#tb";
    opt.AllowEdit = false;
    opt.AllowDbl = false;
    return opt;
};